package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.Result;
import io.renren.dao.StockOrdermxDao;
import io.renren.dto.StockOrderDTO;
import io.renren.dto.StockOrdermxDTO;
import io.renren.entity.StockOrdermxEntity;
import io.renren.service.StockOrdermxService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 食材采购明细表
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-11-22
 */
@Service
public class StockOrdermxServiceImpl extends CrudServiceImpl<StockOrdermxDao, StockOrdermxEntity, StockOrdermxDTO> implements StockOrdermxService {

    @Autowired
    private StockOrdermxDao stockOrdermxDao;

    @Override
    public QueryWrapper<StockOrdermxEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<StockOrdermxEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public void updateUnitPrice(StockOrdermxDTO dto) {
        dto.setSubStatus(1);
        update(dto);
    }

    @Override
    public Result updatePhoto(StockOrdermxDTO dto) {
        StockOrdermxDTO ordermxDTO = stockOrdermxDao.gysMx(dto.getStockOrdermxId());
        if(0 != ordermxDTO.getSubStatus()){
            dto.setStatus(4);
            dto.setSubStatus(1);
            update(dto);
            return new Result();
        }else {
            Result result = new Result();
            result.setMsg("供应商未报价，不能审核");
            result.setCode(5000);
            return result;
        }

    }

    /**
     * 查询供应商下食物信息
     *
     * @param orderId
     * @param supplierId
     * @return
     */

    @Override
    public List<StockOrdermxDTO> detail(long orderId, long supplierId) {
        return stockOrdermxDao.detailed(orderId, supplierId);
    }


    @Override
    public List<StockOrdermxDTO> selecSupplierOrder1(long id, long ids) {
        return stockOrdermxDao.selecSupplierOrder1(id, ids);
    }

    /**
     * 查询供应商名称
     *
     * @param id
     * @return
     */
    @Override
    public List<StockOrdermxDTO> gyss(long id) {
        return baseDao.gys(id);
    }

    @Override
    public void deleteOrder(Long id) {
        stockOrdermxDao.deleteOrder(id);
    }

    @Override
    public StockOrdermxDTO getOrderNum(String bgeinDate, String endDate, long supplierId) {
        StockOrdermxDTO orderNum = stockOrdermxDao.getOrderNum(bgeinDate, endDate, supplierId);
        return orderNum;
    }

    @Override
    public List<StockOrdermxDTO> getOrderMx(String bgeinDate, String endDate, long supplierId) {
        List<StockOrdermxDTO> orderMx = stockOrdermxDao.getOrderMx(bgeinDate, endDate, supplierId);
        return orderMx;
    }

    @Override
    public void updateOrder2(long orderId, long foodId, float purchaseNum) {
        stockOrdermxDao.updateOrder2(orderId,foodId,purchaseNum);
    }

    @Override
    public void delectOrder(long orderId, long foodId) {
        stockOrdermxDao.delectOrder1(orderId,foodId);
    }

}